﻿/*********************************************************************************
**                                                                              **
**  Copyright (C) 2021-2025 LiLong                                              **
**  This file is part of CommonUnits.                                           **
**                                                                              **
**  CommonUnits is free software: you can redistribute it and/or modify         **
**  it under the terms of the GNU Lesser General Public License as published by **
**  the Free Software Foundation, either version 3 of the License, or           **
**  (at your option) any later version.                                         **
**                                                                              **
**  CommonUnits is distributed in the hope that it will be useful,              **
**  but WITHOUT ANY WARRANTY; without even the implied warranty of              **
**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               **
**  GNU Lesser General Public License for more details.                         **
**                                                                              **
**  You should have received a copy of the GNU Lesser General Public License    **
**  along with CommonUnits.  If not, see <https://www.gnu.org/licenses/>.       **
**********************************************************************************/
#pragma once

#include "../CommonUnits.h"
#include "../UnitLists.h"

namespace CU
{
inline namespace Frequency
{
namespace Units
{
using Hz  = StandardUnit<"Hz">;
using kHz = DeriveUnit<Hz, "kHz", std::kilo>;
using MHz = DeriveUnit<Hz, "MHz", std::mega>;
using GHz = DeriveUnit<Hz, "GHz", std::giga>;
using THz = DeriveUnit<Hz, "THz", std::tera>;
using PHz = DeriveUnit<Hz, "PHz", std::peta>;
using EHz = DeriveUnit<Hz, "EHz", std::exa>;

using FrequencyList = UnitLists<Hz, kHz, MHz, GHz, THz, PHz, EHz>;
} // namespace Units
using Hertz     = CommonUnits<double, Units::Hz>;
using Kilohertz = CommonUnits<double, Units::kHz>;
using Megahertz = CommonUnits<double, Units::MHz>;
using Gigahertz = CommonUnits<double, Units::GHz>;
using Terahertz = CommonUnits<double, Units::THz>;
using Petahertz = CommonUnits<double, Units::PHz>;
using Exahertz  = CommonUnits<double, Units::EHz>;

namespace Literals
{
constexpr auto operator""_Hz(long double val) { return Hertz(val); }
constexpr auto operator""_kHz(long double val) { return Kilohertz(val); }
constexpr auto operator""_MHz(long double val) { return Megahertz(val); }
constexpr auto operator""_GHz(long double val) { return Gigahertz(val); }
constexpr auto operator""_THz(long double val) { return Terahertz(val); }
constexpr auto operator""_PHz(long double val) { return Petahertz(val); }
constexpr auto operator""_EHz(long double val) { return Exahertz(val); }
} // namespace Literals

template<typename Unit>
inline auto toUnit(double value, const std::string& dest) -> Unit
{
    return toUnitHelper<Unit, Units::FrequencyList>(value, dest);
}
} // namespace Frequency
} // namespace CU
